//
//  FristCell.m
//  AssistantDriving
//
//  Created by dcr on 2017/8/28.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "FirstCell.h"

@interface FirstCell()
@property (nonatomic,strong) UIImageView     *nextImageView;
@property (nonatomic,strong) UIView      *dividingLineView;
@end

@implementation FirstCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    
    NSString * identifier = NSStringFromClass([FirstCell class]);
    FirstCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[FirstCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat padding = kSpace;
    
    CGFloat iconImageViewX = padding;
    CGFloat iconImageViewW = 40;
    CGFloat iconImageViewH = iconImageViewW;
    CGFloat iconImageViewY = (self.height - iconImageViewH) * 0.5f;
    self.iconImageView.frame = CGRectMake(iconImageViewX, iconImageViewY, iconImageViewW, iconImageViewH);
    
    CGFloat titleLabelX = iconImageViewX + iconImageViewW + padding;
    CGFloat titleLabelY = iconImageViewY;
    CGFloat titleLabelW = (self.width - titleLabelX - padding) * 0.5f;
    CGFloat titleLabelH = iconImageViewH;
    self.titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
    
    
    CGFloat nextImageViewW = 10;
    CGFloat nextImageViewH = nextImageViewW;
    CGFloat nextImageViewX = self.width - nextImageViewW - padding;
    CGFloat nextImageViewY = (self.height - nextImageViewH) * 0.5f;
    self.nextImageView.frame = CGRectMake(nextImageViewX, nextImageViewY, nextImageViewW, nextImageViewH);
    
    CGFloat dividingLineViewX = padding;
    CGFloat dividingLineViewW = self.width - 2 * padding;
    CGFloat dividingLineViewH = 0.5f;
    CGFloat dividingLineViewY = self.height - dividingLineViewH;
    self.dividingLineView.frame = CGRectMake(dividingLineViewX, dividingLineViewY, dividingLineViewW, dividingLineViewH);
}

- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [UIImageView new];
        _iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        _iconImageView.clipsToBounds = YES;
        _iconImageView.layer.borderColor = [UIColor clearColor].CGColor;
        _iconImageView.layer.borderWidth = 0.5f;
    }
    return _iconImageView;
}

- (UILabel *)titleLabel {
    
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = KC02_2c2c2c;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

- (UIImageView *)nextImageView {
    if (!_nextImageView) {
        _nextImageView = [UIImageView new];
        _nextImageView.contentMode = UIViewContentModeScaleAspectFill;
        _nextImageView.clipsToBounds = YES;
        _nextImageView.layer.borderColor = [UIColor clearColor].CGColor;
        _nextImageView.layer.borderWidth = 0.5f;
        _nextImageView.image = [UIImage imageNamed:@"arrow_right"];
    }
    return _nextImageView;
}

- (UIView *)dividingLineView {
    if (!_dividingLineView) {
        _dividingLineView = [UIView new];
        _dividingLineView.backgroundColor = [UIColor lightGrayColor];
        _dividingLineView.alpha = 0.3f;
    }
    return _dividingLineView;
}

- (void)setupSubviews {
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.nextImageView];
    [self.contentView addSubview:self.dividingLineView];
}

+ (CGFloat)cellHeight {
    return 60;
}

@end
